package com.xbongbong.paas.help;

import com.xbongbong.paas.domain.entity.PaasProcessDataEntity;
import com.xbongbong.paas.feign.WorkOrderV2WorkflowFeignClient;
import com.xbongbong.paas.pojo.workflow.execute.dto.WorkflowUpdateFlowStatusDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 吴峰
 * @date 2022/12/15 15:28
 */
@Component
public class FlowStatusHelp {

    @Resource
    private WorkOrderV2WorkflowFeignClient workOrderV2WorkflowFeignClient;
    @Resource
    private FormDataHelp formDataHelp;

    public void updateFormDataStatus(PaasProcessDataEntity paasProcessDataEntity, Integer flowStatus) throws XbbException {
        if (XbbRefTypeEnum.workOrderV2SupportApproval().contains(paasProcessDataEntity.getBusinessType())) {
            WorkflowUpdateFlowStatusDTO workflowUpdateFlowStatusDTO = new WorkflowUpdateFlowStatusDTO(paasProcessDataEntity.getCorpid(),
                    paasProcessDataEntity.getFormDataId(), paasProcessDataEntity.getBusinessType(), paasProcessDataEntity.getDel(), flowStatus);
            workOrderV2WorkflowFeignClient.updateFlowStatus(workflowUpdateFlowStatusDTO, LocaleContextHolder.getLocale().toString());
        } else {
            formDataHelp.updateFormDataStatus(paasProcessDataEntity, flowStatus);
        }
    }
}
